package com.fedoom.frontend.views;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.*;
/**
 * I realized that many features were shared between all the 'sub views', so I 
 * decided to create a Parent class for them.  It does the basics of creating 
 * a MODAL JDialog, setting up a layout, and provides a method for adding
 * JLabel/JComponent pairs to the view
 * @author tony
 *
 */
@SuppressWarnings("serial")
public class ModalView extends JDialog{
	
	private JButton okButton;
	private JPanel compPanel, panel;
	private ArrayList<JComponent> collection= new ArrayList<JComponent>();
	final protected JFileChooser fileChooser=new JFileChooser();
	
	/**
	 * Constructor takes owner and sets it as the parent of this JDialog
	 * @param owner	JFrame that is the parent of this JDialog
	 */
	public ModalView(JFrame owner)
	{
		super(null,Dialog.ModalityType.APPLICATION_MODAL);
		this.okButton = new JButton("OK");
		//layout
		 panel = new JPanel();
		compPanel = new JPanel();
		panel.setLayout(new BorderLayout());
		compPanel.setLayout(new GridLayout(0,2));
		
		panel.add(okButton,BorderLayout.SOUTH);
		panel.add(compPanel, BorderLayout.CENTER);
//		panel.add(okButton);
		
		this.okButton.setDefaultCapable(true);
		((GridLayout)this.compPanel.getLayout()).setVgap(10);
		
		this.setContentPane(panel);

		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.pack();
	}
/**
 * 	constructor - avoid using this constructor
 */
	public ModalView(){
		this(null);
	}
	/**
	 * Adds a JLabel, JComponent pair to the UI 
	 * @param label	JLabel that needs adding to the UI
	 * @param comp	JComponent (JTextArea, JCheckBox, etc) that needs adding to UI
	 */
	public void addLabelComponentPair(JComponent label, JComponent comp)
	{
		this.compPanel.add(label);
		
		this.compPanel.add(comp);
		collection.add(comp);
		
	}
	
	/**
	 * Method to add a listener for the okButton
	 * @param okListener	The ActionListener that should respond to okButton
	 */
	public void addOKListener(ActionListener okListener){
		
		//don't actual perform any actions on the GUI elements from here.
		//This just links back to the controller which then links to the model
		//The model has the actual logic which the element has asked to perform
		
		okButton.addActionListener(okListener);
	}



	/**
	 * Sets up the View with a name, title & listener
	 * @param viewName	Name that can be used to identify the view
	 * @param viewTitle	Title that will appear on title bar of the JDialog
	 * @param OKListener	Listener that will respond to OK clicks
	 */
	public void setInfo(String viewName, String viewTitle, ActionListener OKListener)
	{
		this.setTitle("Start Single Player");
		this.setName("singleView");
		this.addOKListener(OKListener);
	}	

}
